<?php

require_once 'propel/engine/builder/om/php5/PHP5ObjectBuilder.php';

/**
 * Generates a PHP5 base Object class for user object model (OM).
 *
 * This class produces the base object class (e.g. BaseMyTable) which contains all
 * the custom-built accessor and setter methods.
 *
 * @package    infra.propel.php5
 */
class SeoObjectBuilder extends PHP5ObjectBuilder 
{

	/**
	 * Adds the methods related to refreshing, saving and deleting the object.
	 * @param      string &$script The script will be modified in this method.
	 */
	protected function addManipulationMethods(&$script)
	{
		parent::addManipulationMethods($script);
		
		$this->addSaveHooks($script);
	}
	
	/**
	 * Adds the save hook methods.
	 * @param      string &$script The script will be modified in this method.
	 */
	protected function addSaveHooks(&$script)
	{
		$table = $this->getTable();
		$createdAtColumn = $table->getColumn('created_at');
		$updatedAtColumn = $table->getColumn('updated_at');
		
		$script .= "
	/**
	 * Code to be run before inserting to database
	 * @param PropelPDO \$con
	 * @return boolean
	 */
	public function preInsert(PropelPDO \$con = null)
	{";
		
		if($createdAtColumn)
		$script .= "
    	\$this->setCreatedAt(time());";
		
		if($updatedAtColumn)
		$script .= "
    	\$this->setUpdatedAt(time());";
		
		$script .= "
		return true;
	}
	

	/**
	 * Code to be run before updating the object in database
	 * @param PropelPDO \$con
	 * @return boolean
	 */
	public function preUpdate(PropelPDO \$con = null)
	{";
		
		if($updatedAtColumn)
		$script .= "
    	\$this->setUpdatedAt(time());";
		
		$script .= "
		return true;
	}
	";
		
	}
	
}
